package com.start.workflow.vo;

import com.alibaba.fastjson2.JSONObject;
import com.start.common.entity.StartBaseUser;
import com.start.security.StartTokenTools;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;


@Data
public class ActivitTaskHandlerAction {
    public static final Integer Action_agree = 1;
    public static final Integer Action_reject = 0;
    @Schema(name = "处理类型  0 驳回 1 同意")
    private int action = 0;
    @Schema(name = "处理人姓名")
    private String handlerUserId;
    @Schema(name = "处理人姓名")
    private String handlerUserName;
    @Schema(name = "处理人用户类型")
    private String startUserType;
    @Schema(name = "处理人意见")
    private String handlerOpinion;

    public String toJson() {
        return JSONObject.toJSONString(this);
    }

    public static ActivitTaskHandlerAction agree(String handlerOpinion) {
        StartBaseUser startBaseUser = StartTokenTools.getCurrentUser().getStartBaseUser();
        return agree(startBaseUser.getId(), startBaseUser.getUserFinalName(), handlerOpinion);
    }

    public static ActivitTaskHandlerAction agree(String handlerUserId, String handlerUserName, String handlerOpinion) {
        ActivitTaskHandlerAction handlerAction = createDefault(handlerUserId, handlerUserName, handlerOpinion);
        handlerAction.setAction(Action_agree);
        return handlerAction;
    }

    public static ActivitTaskHandlerAction reject(String handlerOpinion) {
        StartBaseUser startBaseUser = StartTokenTools.getCurrentUser().getStartBaseUser();
        return reject(startBaseUser.getId(), startBaseUser.getUserFinalName(), handlerOpinion);
    }

    public static ActivitTaskHandlerAction reject(String handlerUserId, String handlerUserName, String handlerOpinion) {
        ActivitTaskHandlerAction handlerAction = createDefault(handlerUserId, handlerUserName, handlerOpinion);
        handlerAction.setAction(Action_reject);
        return handlerAction;
    }

    private static ActivitTaskHandlerAction createDefault(String handlerUserId, String handlerUserName, String handlerOpinion) {
        ActivitTaskHandlerAction handlerAction = new ActivitTaskHandlerAction();
        handlerAction.setHandlerOpinion(handlerOpinion);
        handlerAction.setHandlerUserName(handlerUserName);
        handlerAction.setHandlerUserId(handlerUserId);
        return handlerAction;
    }
}
